import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/entity/expert/plan_Info_entity.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/utils/mode_config.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/utils/widget_utils.dart';
import 'package:ball_lion/module/pick/items/expert_record_tag.dart';
import 'package:ball_lion/widgets/focus_button.dart';

import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'items/expert_first_tag.dart';

class ExpertInfoView {
  ExpertInfoView({this.planInfo, this.toFocus, this.toDetail});

  final PlanInfoEntity? planInfo;
  int? roomId = Get.parameters['roomId'].toInt();
  final void Function()? toFocus;
  final void Function()? toDetail;

  bool get focus => (planInfo?.isFocus ?? 0) > 0;

  _expertName() => QsText(
        planInfo?.expertName ?? "",
        needCenter: true,
        fontWeight: FontWeight.w500,
        color: Colours.text292D32,
      ).tap(() {
        Utils.onEvent('plan_detail_expert_view', params: {
          'expert_id': planInfo?.expertId,
          'param2': roomId == null ? '0' : '1'
        });
        toDetail?.call();
      });

  // _expertFocusBtn() => OutlinedButton(
  //     onPressed: toFocus,
  //     style: OutlinedButton.styleFrom(
  //       minimumSize: Size(56, 24),
  //       fixedSize: Size(56, 24),
  //       maximumSize: Size(56, 24),
  //       elevation: 0,
  //       padding: EdgeInsets.zero,
  //       foregroundColor: focus ? _grey99 : Colors.white,
  //       backgroundColor: focus ? _greyEE : Colours.blue2766D6,
  //       side: BorderSide.none,
  //       shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
  //     ),
  //     child: QsText(
  //       focus ? "已关注" : "关注",
  //       style: const TextStyle(height: 1.4, fontSize: 13),
  //     ));
  // CommonButton(
  //   onPressed: clickToFocus,
  //   text: focus ? "已关注" : "关注",
  //   minHeight: 24,
  //   minWidth: 56,
  //   textStyle: TextStyle(fontSize: 13,fontWeight: FontWeight.w400),
  //   foregroundColor: focus ? _grey99 : Colors.white,
  //   backgroundColor: focus ? _greyEE : Colours.main_color,
  // );

  _expertHead({double size = 40}) {
    return Container(
      clipBehavior: Clip.hardEdge,
      decoration: const BoxDecoration(shape: BoxShape.circle),
      child: CachedNetworkImage(
          fit: BoxFit.cover,
          width: size,
          height: size,
          imageUrl: planInfo?.expertLogo ?? "",
          placeholder: (context, url) => Container(),
          errorWidget: (context, url, error) => Container()),
    ).tap(() {
      Utils.onEvent('plan_detail_expert_view', params: {
        'expert_id': planInfo?.expertId,
        'param3': roomId == null ? '0' : '1'
      });
      toDetail?.call();
    });
  }

  expertBar() {
    return Row(
      children: [
        _expertHead(size: 30),
        const SizedBox(width: 16),
        _expertName(),
        const Spacer(),
        FocusButton(
          planInfo?.isFocus ?? 0,
          expertId: planInfo?.expertId,
          onTap: (value) {
            planInfo?.isFocus = value;
          },
        ),
        Container(width: 16),
      ],
    );
  }

  Widget expertRow({GlobalKey? key}) {
    return Container(
      key: key,
      child: planInfo == null
          ? null
          : Row(
              children: [
                _expertHead(),
                const SizedBox(width: 8),
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        _expertName(),
                        if (ModeConfig.expertRecord &&
                            planInfo?.firstTag.hasValue == true) ...[
                          Container(width: 4),
                          ExpertFirstTag(tag: planInfo!.firstTag!)
                        ]
                      ],
                    ),
                    if (ModeConfig.expertRecord &&
                        planInfo?.secondTag.hasValue == true) ...[
                      const SizedBox(height: 2),
                      ExpertRecordTag(text: planInfo?.secondTag ?? '', type: 5)
                    ]
                  ],
                ),
                const Spacer(),
                FocusButton(planInfo?.isFocus ?? 0,
                    expertId: planInfo?.expertId, onTap: (value) {
                  Utils.onEvent('plan_detail_expert_follow', params: {
                    "expert_id": planInfo?.expertId,
                    'follow': value,
                    'param3': roomId == null ? '0' : '1'
                  });
                  planInfo?.isFocus = value;
                })
              ],
            ),
    );
  }
}
